package main

import (
	"context"
	"fmt"
	"go-learn/config"
	"go-learn/global"
	"go-learn/initialize"
	"go-learn/model/pb"
	"go.mongodb.org/mongo-driver/bson"
)

func main() {
	global.Config = config.Init()
	global.GvaMongodb = initialize.Mongodb()

	for i := 0; i < 100; i++ {
		go func() {
			for {
				Find(i)
			}
		}()
	}
	for {

	}
}

func Find(index int) {
	coll := global.GvaMongodb.Collection(global.MongoCollection)
	filter := bson.M{}
	res := pb.User{}
	err := coll.FindOne(context.TODO(), filter).Decode(&res)
	if err != nil {
		fmt.Printf("thread %d err: %s\n", index, err.Error())
	}
	fmt.Printf("thread %d find: %v\n", index, res)
}
